<template>
  <div class="page setting">
    <div class="scroll-view">
      <customHeader middleTitle="设置"/>
      <div class="page-body">
        <ul class="mine-options">
          <li class="option-item"
              @click="linkToChangePhone">
              <span class="left">修改手机号</span>
              <div class="right">
                <span class="value"></span>
                <span class="right-icon"><i class="zhk-list_rarrow"></i></span>
              </div>
          </li>
          <li class="option-item"
              @click="linkToChangePassword">
              <span class="left">修改密码</span>
              <div class="right">
                <span class="value"></span>
                <span class="right-icon"><i class="zhk-list_rarrow"></i></span>
              </div>
          </li>
          <!-- <li class="option-item"
              @click="linkToAccountDel">
              <span class="left">账号注销</span>
              <div class="right">
                <span class="value"></span>
                <span class="right-icon"><i class="zhk-list_rarrow"></i></span>
              </div>
          </li> -->
        </ul>
        <ul class="mine-options">
          <li class="option-item" @click="linkToAbout">
              <span :class="hasNew?'left new':'left'">关于</span>
              <div class="right">
                <span v-if="appVersion" class="value">v{{appVersion}}</span>
                <span class="right-icon"><i class="zhk-list_rarrow"></i></span>
              </div>
          </li>
          <li class="option-item"
              @click="handleContactService">
              <span class="left">联系客服</span>
              <div class="right">
                <span class="value">400-109-9960</span>
                <span class="right-icon"><i class="zhk-list_rarrow"></i></span>
              </div>
          </li>
        </ul>
        <div class="btn-wrap">
          <div class="btn"
               @click="exitApp">退出登录</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import customHeader from "../../components/header/header";
import jsBridge from "../../tools/jsBridge.js";
import { Toast, MessageBox } from "mint-ui";

export default {
  name: "setting",
  data() {
    return {
      hasNew: false,
      appVersion: "",
      isAndroid: false
    };
  },
  methods: {
    linkToChangePhone() {
      this.$router.push({ path: "/setting/changePhone" });
    },
    linkToChangePassword() {
      this.$router.push({ path: "/setting/changePassword" });
    },
    linkToAbout() {
      this.$router.push({ path: "/setting/about" });
    },
    linkToAccountDel() {
      this.$router.push({ path: "/setting/accountDel" });
    },
    handleContactService() {
      let params = {
        tel: "4001099960"
      };
      jsBridge.callUp(params);
    },
    exitApp() {
      MessageBox({
        title: "",
        message: "您确定要退出登录吗？",
        cancelButtonClass: "cancelBlue",
        showCancelButton: true,
        confirmButtonText: "取消",
        cancelButtonText: "确定"
      }).then(action => {
        if (action === "confirm") {
        } else {
          localStorage.clear();
          AppUtil.call(AppUtil.APIS.LOGOUT);
        }
      });
    },
    getPlatform() {
			let ua = navigator.userAgent.toLowerCase();
			if (ua.indexOf('android') >= 0) {
				this.isAndroid = true;
			} else {
				this.isAndroid = false;
			}
		},
    getCurrentAppVersion(callback) {
      let self = this;
      jsBridge.getCurrentAppVersion(result => {
        if (result.success.toString() == "true") {
          this.appVersion = result.resultObject;
          callback && callback();
        } else {
          Toast("获取APP版本失败！");
        }
      });
    },
    checkAppUpgrade(callBack) {
			let param = { appVersion: this.appVersion, type: '3', platform: this.isAndroid ? '1' : '2', h5Module: {} };
			this.ajax({
				url: '/app/version/upgrade.do',
				type: 'post',
				controlLoading: false,
				data: param,
			})
				.then(res => {
					if (res != null && res.success) {
						callBack && callBack(res.resultObject);
					} else {

					}
				})
				.catch(err => {

				});
		},
  },
  mounted() {
    this.getPlatform();
    let self = this;
    setTimeout(() => {
      self.getCurrentAppVersion(() => {
        self.checkAppUpgrade(resultObject => {
          if (resultObject && resultObject && resultObject.appVersion) {
            self.hasNew = true;
          }
        });
      });
    }, 100);
  },
  components: {
    customHeader
  }
};
</script>
<style lang='scss' scoped>
@import "setting";
</style>
